/**
 * Created by Boyz.X on 2015/9/21.
 */
appModule.controller('tabfollowCtr', function ($scope,$state,CommonUtils,$http) {
  $http.post( webserver + 'com.chinasie.s2c.users.users.querymessage.biz.ext', {
    userId:"222222"
  }).success(function(data){
    $scope.messages = data.messages;
    angular.forEach(data.messages, function (message, index){
      var myDate = new Date();
      var mydata = new Date();
      var myDate =  myDate.toLocaleString( );
      var mydata = mydata.getFullYear();
      if(message.sendTime.substr(0,4) == myDate.substr(0,4)){
        Date1 = message.sendTime.substr(5,6).split('-');
        Date2 = myDate.substr(5,6).split('/');
        Date3 = message.sendTime.split('.');
        Date3 = Date3[0].split(' ');
        if(Date1[0] == Date2[0]){
          if(Date1[1] == Date2[1]){
            message.sendTime = "今天" + Date3[1];
          }else if((Date2[1] - Date1[1]) == 1){
            message.sendTime = "昨天" + Date3[1];
          }else{
            message.sendTime = message.sendTime.substr(5,6) + Date3[1];
          }
        }else{
          message.sendTime = message.sendTime.substr(5,6) + Date3[1];
        }
      }else{
        message.sendTime = message.sendTime.substr(5,6) + Date3[1];
      }
    });
  });
  $scope.showMessage = function(data){
    if(data != null){
      return true;
    }
    return false;
  };
  $scope.Detial = function(cid,cname){
    CommonUtils.goTo('followDetial',{cid:JSON.stringify(cid),cname:JSON.stringify(cname)});
  };
  $scope.goContacts = function(){
    $state.go('contacts');
  }

});
